package com.zzg.datastructure.huffmantree.entity;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.Objects;

/**
 * @Author zhengzg
 * @Date 2022-09-29
 * @Version v1.0
 */
@Getter
@Setter
@ToString(of = {"value"})
public class Node implements Comparable<Node>{

    /**
     * 结点权值
     */
    private int value;

    /**
     * 指向左字节点
     */
    private Node left;

    /**
     * 指向右字节点
     */
    private Node right;

    public Node(int value) {
        this.value = value;
    }

    /**
     * 前序遍历
     */
    public void preOrder() {
        System.out.println(this);
        if (Objects.nonNull(this.left)) {
            this.left.preOrder();
        }

        if (Objects.nonNull(this.right)) {
            this.right.preOrder();
        }
    }

    // 表示从小到大排序
    @Override
    public int compareTo(Node o) {
        return this.value - o.value;
    }
}
